#pragma once
#ifndef SPRITE_H
#define SPRITE_H

#include "Object.h"
#include <raylib.h>
#include <random>

class sprite:public Object
{
    public :
        sprite(){}
        float Velocity=150.0f;

        bool isLive;
        bool moving;

        static float deltaTime;
        virtual vector<float> getCollisionBox()=0;

        int direction = 0;
        int getDirection();

        float frameTime = 0.2f;  // 每帧停留时间
        float frameTimer = 0.0f; // 动画帧时长计时器

        void setDirection(int direction);
        void setVelocity(float vel);
        void setLive(bool islive);
        void run_right(float step);
        void run_down(float step);
        void run_left(float step);
        void run_up(float step);   

};
inline bool getCollision(Rectangle rect1,Rectangle rect2)
{
    // 增大容差
    float hTolerance = 0.5f;  // 水平容差
    float vTolerance = 1.0f;  // 垂直容差
    
    float rect1Box[4] = {
        rect1.x + hTolerance, 
        rect1.y + vTolerance, 
        rect1.x + rect1.width - hTolerance, 
        rect1.y + rect1.height - vTolerance
    };
    
    float rect2Box[4] = {
        rect2.x + hTolerance, 
        rect2.y + vTolerance, 
        rect2.x + rect2.width - hTolerance, 
        rect2.y + rect2.height - vTolerance
    };
    
    if (rect1Box[0] < rect2Box[2] &&
        rect1Box[2] > rect2Box[0] &&
        rect1Box[1] < rect2Box[3] &&
        rect1Box[3] > rect2Box[1]) {
            return true;
        }
    return false;
}

inline int getRand(int min, int max) {
    return (std::rand() % (max - min + 1)) + min;
}




// public boolean isHit(Shot shot, Tanker tank)
//     {
//         int [] shotBox = shot.getCollisionBox();
//         int [] tankBox = tank.getCollisionBox();
//         return (shotBox[0] < tankBox[2] &&
//                 shotBox[2] > tankBox[0] &&
//                 shotBox[1] < tankBox[3] &&
//                 shotBox[3] > tankBox[1]);
//     }

#endif